<template>
	<view class="container">
		<view class="form-item">
			<text class="label">打印机编码：</text>
			<input class="input" v-model="printerCode" placeholder="请输入打印机编码" />
		</view>
		<view class="form-item">
			<text class="label">检验码：</text>
			<input class="input" v-model="checkCode" placeholder="请输入检验码" />
		</view>
		<view class="form-item">
			<text class="label">备注：</text>
			<input class="input" v-model="remark" placeholder="请输入备注" />
		</view>

		<u-button class="submit-button" type="primary" @click="submitForm">绑定打印机</u-button>
	</view>
</template>

<script>
	import {
		addPrinter
	} from '@/api/printer.js'; // 添加打印机接口
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				printerCode: '', // 打印机编码
				checkCode: '', // 检验码
				remark: '', // 备注
			};
		},
		computed: {
			...mapGetters(["isLogin", "uid", "userType"]),
		},
		methods: {
			// 提交表单数据
			submitForm() {
				if (!this.printerCode || !this.checkCode) {
					return this.$util.Tips({
						title: '请填写完整信息'
					});
				}

				const params = {
					printerCode: this.printerCode,
					saleId: this.uid,
					checkCode: this.checkCode,
					remark: this.remark,
				};

				addPrinter(params)
					.then(res => {
						this.$util.Tips({
							title: res.value
						});
					})
					.catch(err => {
						this.$util.Tips({
							title: err || '绑定失败'
						});
					});
			},
		},
	};
</script>

<style>
	.container {
		padding: 20px;
	}

	.form-item {
		margin-bottom: 20px;
		display: flex;
		align-items: center;
	}

	.label {
		width: 100px;
		font-weight: bold;
	}

	.input {
		flex: 1;
		border: 1px solid #ccc;
		padding: 10px;
		border-radius: 4px;
	}

	.submit-button {
		margin-top: 20px;
		width: 100%;
	}
</style>